﻿@inherits TscComponentBase

@if (JsonObject is not null)
{
    foreach (var (name, logTree) in JsonObject)
    {
        if (!string.IsNullOrEmpty(logTree.ToString()) && logTree.IsValueType)
        {
            <div class="d-flex mb-4">
                <div class="px-2 @(MarginLeftClass) @(MarginRightClass) my-auto fill-background text-no-wrap" style="border-radius: 6px;height: 25px;text-align:center;">
                    <span class="emphasis2--text btn">@name</span>
                </div>
                <span class="body2 regular2--text my-auto">
                    :@logTree.ToMarkUpString(Search)
                </span>
            </div>
        }
        else if (logTree.IsObject)
        {
            <div class="d-flex mb-4">
                @if (!Small)
                {
                    <SButton Icon Class="ml-n5" OnClick="() => logTree.Expanded =!logTree.Expanded">
                        <SIcon Size="24" Color="regular2">
                            @(logTree.Expanded ? IconConstants.MenuDown : IconConstants.MenuRight)
                        </SIcon>
                    </SButton>
                }
                <div class="px-2 @(MarginRightClass) my-auto fill-background" style="border-radius: 6px;height: 25px;text-align:center;">
                    <span class="emphasis2--text btn">@name</span>
                </div>
                <span class="body2 primary--text my-auto hover-pointer" @onclick="() => logTree.Expanded =!logTree.Expanded">@(logTree.Expanded ? "{" : "{ ... }")</span>
            </div>
            @if (logTree.Expanded)
            {
                <div class="pl-5 mb-4">
                    <LogView Search=@Search CloseAotoExpand="true" JsonObject=logTree.ToObject() />
                    <div class="body2 primary--text">}</div>
                </div>
            }
        }
        else if (logTree.IsArray)
        {
            <div class="d-flex mb-4">
                @if (!Small)
                {
                    <SButton Icon Class="ml-n5" OnClick="() => logTree.Expanded =!logTree.Expanded">
                        <SIcon Size="24" Color="regular2">
                            @(logTree.Expanded ? IconConstants.MenuDown : IconConstants.MenuRight)
                        </SIcon>
                    </SButton>
                }
                <div class="px-2 @(MarginRightClass) my-auto fill-background" style="border-radius: 6px;height: 25px;text-align:center;">
                    <span class="emphasis2--text btn">@name</span>
                </div>
                <span class="body2 primary--text my-auto hover-pointer" @onclick="() => logTree.Expanded =!logTree.Expanded">@(logTree.Expanded ? "[" : "[ ... ]")</span>
            </div>
            @if (logTree.Expanded)
            {
                <div class="pl-5 mb-4">
                    <LogView Search=@Search CloseAotoExpand="true" JsonArray=logTree.ToArray() />
                    <div class="body2 primary--text">]</div>
                </div>
            }
        }
    }
}
else if (JsonArray is not null)
{
    foreach (var logTree in JsonArray)
    {
        if (logTree.IsValueType)
        {
            <span class="body2 regular2--text">
                :@logTree.ToMarkUpString(Search)
            </span>
        }
        else if (logTree.IsObject)
        {
            <div class="d-flex mb-4">
                <SButton Icon Class="ml-n5" OnClick="() => logTree.Expanded =!logTree.Expanded">
                    <SIcon Size="24" Color="regular2">
                        @(logTree.Expanded ? IconConstants.MenuDown : IconConstants.MenuRight)
                    </SIcon>
                </SButton>
                <span class="body2 primary--text my-auto hover-pointer" @onclick="() => logTree.Expanded =!logTree.Expanded">@(logTree.Expanded ? "{" : "{ ... }")</span>
            </div>
            @if (logTree.Expanded)
            {
                <div class="pl-5 mb-4">
                    <LogView Search=@Search CloseAotoExpand="true" JsonObject=logTree.ToObject() />
                    <div class="body2 primary--text">}</div>
                </div>
            }
        }
        else if (logTree.IsArray)
        {
            <div class="d-flex mb-4">
                <SButton Icon Class="ml-n5" OnClick="() => logTree.Expanded =!logTree.Expanded">
                    <SIcon Size="24" Color="regular2">
                        @(logTree.Expanded ? IconConstants.MenuDown : IconConstants.MenuRight)
                    </SIcon>
                </SButton>
                <span class="body2 primary--text my-auto hover-pointer" @onclick="() => logTree.Expanded =!logTree.Expanded">@(logTree.Expanded ? "[" : "[ ... ]")</span>
            </div>
            @if (logTree.Expanded)
            {
                <div class="pl-5 mb-4">
                    <LogView Search=@Search CloseAotoExpand="true" JsonArray=logTree.ToArray() />
                    <div class="body2 primary--text">]</div>
                </div>
            }
        }
    }
}